SQL_TABLE_MAPPING='''
select
    distinct t.schema_type,
    t.id,
    t.table_schema,
    t.table_name,
    t.table_comment,
    t.src_schema_type,
    t.src_table_schema,
    t.src_table_name,
    case
        when n.db_layer = 2 
                       then a.table_comment
        when n.db_layer = 3
                       then b.table_comment
        else c.table_comment
    end src_table_comment,
    t.column_value_rules,
    d.user_name create_user_name
from
    etl_ctl_table_relation t
join etl_ctl_data_conn n 
    on t.src_schema_type = n.db_type
    and t.src_table_schema = n.db_name
left join etl_ctl_table_mapping a 
    on t.src_schema_type = a.schema_type
    and t.src_table_name = a.table_name
    and t.src_table_schema = a.table_schema
left join etl_ctl_table_relation b 
    on t.src_schema_type = b.schema_type
    and t.src_table_name = b.table_name
    and t.src_table_schema = b.table_schema
left join etl_ctl_table c 
    on	t.src_schema_type = c.schema_type
    and t.src_table_name = c.table_name
    and t.src_table_schema = c.table_schema
left join etl_user d 
    on t.create_user_id = d.user_id
where
    1 = 1
order by t.id desc;
'''

SQL_REPORT_INTERFACE='''
select 
    a.id,
    a.report_id,
    a.interface_name,
    a.interface_code ,
    a.interface_db_type ,
    a.interface_db_name ,
    a.interface_sql,
    a.is_paging ,
    a.is_date_option ,
    a.is_total ,
    a.is_second_table ,
    a.alarm_type ,
    a.interface_desc ,
    a.is_login_visit ,
    b.report_name ,
    c.module_name ,
    d.platform_name ,
    u.user_name 
from etl_report_interface a 
join etl_report_info b on a.report_id = b.id 
join etl_report_module c on b.module_id = c.id 
join etl_report_platform d on c.platform_id = d.id 
join etl_user u on a.create_user_id = u.user_id
where 1 = 1 
'''

SQL_REPORT_INTERFACE_DETAIL = '''
select 
t.id,
t.report_id,
t.interface_name,
t.interface_code,
t.interface_db_type,
t.interface_db_name,
t.interface_desc,
t.interface_sql,
t.is_paging,
t.is_login_visit,
t.is_second_table,
t.is_date_option,
t.alarm_type
from etl_report_interface t
where t.id = %s
limit 1
'''

SQL_REPORT_INTERFACE_PARA = '''
select
    id,
    interface_id,
	interface_para_code ,
	interface_para_name,
	interface_para_position,
	interface_para_type ,
	interface_data_type ,
	interface_para_default,
    interface_show_flag,
    interface_export_flag,
    interface_show_desc,
    interface_para_desc
from
	etl_interface_para
'''

SQL_REPORT_PLATFORM ='''
select id,platform_name,platform_desc from etl_report_platform
'''

SQL_REPORT_REPORT ='''
select id,report_name,report_desc,module_id from etl_report_info
'''

SQL_REPORT_MODULE ='''
select id,module_name,module_desc,platform_id from etl_report_module
'''


SQL_REPORT_INFO='''
select p.platform_name,m.module_name ,r.report_name from etl_report_platform p 
join etl_report_module m on m.platform_id = p.id 
join etl_report_info r on r.module_id = m.id;
'''

SQL_REPORT_PLATFORM_MODULE_REPORT = '''
select t1.id as platform_id,t1.platform_name,t2.id as module_id,t2.module_name,t3.id as report_id,t3.report_name from etlctl.etl_report_platform  t1
join etlctl.etl_report_module t2 on t1.id = t2.platform_id 
join etlctl.etl_report_info t3 on t2.id = t3.module_id
'''

SQL_DB_INFO = '''
select 
    id,
    db_name,
    db_conn,
    db_type,
    db_server,
    db_port,
    db_user,
    db_pwd 
from etl_ctl_data_conn;
'''


SQL_ROLE = '''
select
    id,
    name,
    is_admin,
    role_key,
    description
from sys_role
'''